home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / MAINWIND.CPP < prev    next >
C/C++ Source or Header  |  1993-10-12  |  54KB  |  2,218 lines

  1. #include "allwind.h"
  2.  
  3. int critical = 0;
  4.  
  5. void qlist::insert(ent a, int t)
  6.    {
  7.    
  8.    /* class "event list queue" member to insert event */
  9.    
  10.    qlink *h;
  11.    qlink *ph;
  12.    
  13.    if (last)
  14.       {
  15.       ph = last->next;
  16.       h = new qlink(a, NULL, NULL, t);
  17.       last->next = h;
  18.       h->prev = last;
  19.       h->next = ph;
  20.       ph->prev = h;
  21.       last = last->next;
  22.       }
  23.    else
  24.       {
  25.       last = new qlink(a, NULL, NULL, t);
  26.       last->next = last;
  27.       last->prev = last;
  28.       }
  29.    }
  30.  
  31. ent qlist::get(void)
  32.    {
  33.    
  34.    /* class "event list queue" member to get event */
  35.    
  36.    if (last==NULL) return NULL;
  37.    
  38.    return(last->next->e);
  39.    }
  40.  
  41. void qlist::zap(void)
  42.    {
  43.    
  44.    /* class "event list queue" member to zap all events */
  45.    
  46.    qlink* p;
  47.    
  48.    if (last==NULL) return;
  49.    
  50.    p = last->next;
  51.    
  52.    if (last == p)
  53.       {
  54.       last = NULL;
  55.       }
  56.    else
  57.       {
  58.       p->prev->next = p->next;
  59.       p->next->prev = p->prev;
  60.       }
  61.    
  62.    delete p;
  63.    
  64.    }
  65.  
  66. void qlist::clear()
  67.    {
  68.    qlink* l = last;
  69.    
  70.    if (l == NULL) return;
  71.    
  72.    do
  73.       {
  74.       qlink* ll = l;
  75.       l = l->next;
  76.       delete ll;
  77.       }
  78.    while (l!=last);
  79.    }
  80.  
  81. calllist calllists;
  82.  
  83. TMyWindow::TMyWindow(PTWindowsObject AParent, LPSTR ATitle)
  84. : TWindow(AParent, ATitle)
  85.    {
  86.    /* main window initialization */
  87.    
  88.    AssignMenu("COMMANDS");
  89.    PenSize = 1;
  90.    
  91.    /* build the bitmap */
  92.    
  93.    bitCount = 8;
  94.    
  95.    size = sizeof(BITMAPINFOHEADER) + ((1 << bitCount) * sizeof(RGBQUAD));
  96.    BitmapInfo = (BITMAPINFO *)new char[size];
  97.    
  98.    BitmapInfo->bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
  99.    BitmapInfo->bmiHeader.biWidth         = BitMapWidth;
  100.    BitmapInfo->bmiHeader.biHeight        = BitMapHeight;
  101.    BitmapInfo->bmiHeader.biPlanes        = 1;
  102.    BitmapInfo->bmiHeader.biBitCount      = bitCount;
  103.    BitmapInfo->bmiHeader.biCompression   = BI_RGB;
  104.    BitmapInfo->bmiHeader.biSizeImage     = ((((BitmapInfo->bmiHeader.biWidth*BitmapInfo->bmiHeader.biBitCount)+31)/32)*4)*BitmapInfo->bmiHeader.biHeight;
  105.    BitmapInfo->bmiHeader.biXPelsPerMeter = 0;
  106.    BitmapInfo->bmiHeader.biYPelsPerMeter = 0;
  107.    BitmapInfo->bmiHeader.biClrUsed       = 0;
  108.    BitmapInfo->bmiHeader.biClrImportant  = 0;
  109.    
  110.    /* check if a palette exists */
  111.    
  112.    ScreenDC = CreateDC("Display", NULL, NULL, NULL);
  113.    
  114.    if ((GetDeviceCaps(ScreenDC, RASTERCAPS) & RC_PALETTE) == 0)
  115.       {
  116.       EnablePalette = 0;
  117.       }
  118.    else
  119.       {
  120.       EnablePalette = 1;
  121.       }
  122.    
  123.    /* pack memory and eat up a whole bunch of memory */
  124.    
  125.    MemoryBitMap = CreateDIBitmap(ScreenDC, &(BitmapInfo->bmiHeader), 0L, NULL, NULL, DIB_RGB_COLORS);
  126.    
  127.    /* If fail try again after a compact */
  128.    
  129.    if (!MemoryBitMap)
  130.       {
  131.       GlobalCompact(-1);
  132.       MemoryBitMap = CreateDIBitmap(ScreenDC, &(BitmapInfo->bmiHeader), 0L, NULL, NULL, DIB_RGB_COLORS);
  133.       }   
  134.    
  135.    /* this is not fatal, you just loose backing store */
  136.    
  137.    if (!MemoryBitMap) MessageBox(0, "Not enough Memory to repaint", "Warning", MB_OK | MB_ICONEXCLAMATION);
  138.    
  139.    /* clear window */
  140.    
  141.    MemDC = CreateCompatibleDC(ScreenDC);
  142.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  143.    
  144.    PatBlt(MemDC, 0, 0, BitMapWidth, BitMapHeight, WHITENESS);
  145.    
  146.    SelectObject(MemDC, OldBitmap);
  147.    DeleteDC(MemDC);
  148.    DeleteDC(ScreenDC);
  149.    
  150.    /* create printer object */
  151.    
  152.    Printer = new TPrinter;
  153.    
  154.    /* flag that screen clean */
  155.    
  156.    IsNewFile = TRUE;
  157.    IsNewBitmap = TRUE;
  158.    
  159.    /* setup scrollers (LOTS of code for these things) */
  160.    
  161.    Attr.Style |= WS_VSCROLL | WS_HSCROLL;
  162.    Scroller = new TScroller(this, 1, 1, BitMapWidth, BitMapHeight);
  163.    
  164.    /* If palette then build one */
  165.    
  166.    if (EnablePalette)
  167.       {
  168.       MyLogPalette = (LPLOGPALETTE) new char[sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*MaxColors];
  169.       MyLogPalette->palVersion = 0x300;
  170.       MyLogPalette->palNumEntries = 2;
  171.       
  172.       MyLogPalette->palPalEntry[0].peRed = 0;
  173.       MyLogPalette->palPalEntry[0].peGreen = 0;
  174.       MyLogPalette->palPalEntry[0].peBlue = 0;
  175.       MyLogPalette->palPalEntry[0].peFlags = 0;
  176.       
  177.       MyLogPalette->palPalEntry[1].peRed = 255;
  178.       MyLogPalette->palPalEntry[1].peGreen = 255;
  179.       MyLogPalette->palPalEntry[1].peBlue = 255;
  180.       MyLogPalette->palPalEntry[1].peFlags = 0;
  181.       
  182.       ThePalette = CreatePalette(MyLogPalette);
  183.       }
  184.    
  185.    }
  186.  
  187. TMyWindow::~TMyWindow()
  188.    {
  189.    int i;
  190.    
  191.    /* clean things up */
  192.    
  193.    delete Printer;
  194.    delete Scroller;
  195.    DeleteObject(MemoryBitMap);
  196.    delete EditboxWindow;
  197.    delete ListboxWindow;
  198.    delete CommandWindow;
  199.    
  200.    /* if palette clean it too */
  201.    
  202.    if (EnablePalette)
  203.       {
  204.       DeleteObject(ThePalette);
  205.       delete MyLogPalette;
  206.       }
  207.    
  208.    free(gcstack);
  209.    free(hash_table);
  210.    
  211.    /* Note Bitmap index 0 belongs to CLipboard */
  212.    
  213.    for (i=1;i<MaxBitCuts;i++)
  214.    if (CutBmp[i].CutFlag) DeleteObject(CutBmp[i].CutMemoryBitMap);
  215.    
  216.    // Borland will take care of freeing most mallocs (I hope)
  217.    
  218.    //    GlobalUnlock(HashHandle);
  219.    //    GlobalFree(HashHandle);
  220.    
  221.    //    GlobalUnlock(StackHandle);
  222.    //    GlobalFree(StackHandle);
  223.    
  224.    }
  225.  
  226. void TMyWindow::WMGetDlgCode( RTMessage msg )
  227.    {
  228.    TWindow::DefWndProc( msg );
  229.    msg.Result |= DLGC_WANTARROWS;
  230.    }
  231.  
  232. void TMyWindow::WMKeyDown(RTMessage Msg)
  233.    { 
  234.    callthing *callevent;
  235.    
  236.    // if keyboard was on and up and down is enabled then continue
  237.    
  238.    if (keyboard_on == 2)
  239.       {
  240.       
  241.       // if key is down skip it
  242.       
  243.       if (!(Msg.LParam & 0x40000000))
  244.          {
  245.          callevent = new callthing;
  246.          
  247.          callevent->func = keyboard_keydown;
  248.          callevent->arg1 = Msg.WParam;
  249.          callevent->kind = 2;
  250.          
  251.          calllists.insert(callevent,2);
  252.          checkqueue();
  253.          //        PostMessage(MainHWindow, WM_CHECKQUEUE, 0, 0);
  254.          }
  255.       }
  256.    
  257.    // scroll main window with arrow keys
  258.    
  259.    switch (Msg.WParam)
  260.       {
  261.       case VK_UP:
  262.          {
  263.          Scroller->ScrollBy(0,-Scroller->YLine);
  264.          break;
  265.          }
  266.       case VK_DOWN:
  267.          {
  268.          Scroller->ScrollBy(0,Scroller->YLine);
  269.          break;
  270.          }
  271.       case VK_LEFT:
  272.          {
  273.          Scroller->ScrollBy(-Scroller->XLine,0);
  274.          break;
  275.          }
  276.       case VK_RIGHT:
  277.          {
  278.          Scroller->ScrollBy(Scroller->XLine,0);
  279.          break;
  280.          }
  281.       
  282.       // else do your normal stuff
  283.       
  284.       default:
  285.          {
  286.          DefWndProc( Msg );
  287.          break;
  288.          }
  289.       }
  290.    }
  291.  
  292. void TMyWindow::WMKeyUp(RTMessage Msg)
  293.    { 
  294.    callthing *callevent;
  295.    
  296.    // if keyboard was on and up and down is enabled then continue
  297.    
  298.    if (keyboard_on == 2)
  299.       {
  300.       callevent = new callthing;
  301.       
  302.       callevent->func = keyboard_keyup;
  303.       callevent->arg1 = Msg.WParam;
  304.       callevent->kind = 2;
  305.       
  306.       calllists.insert(callevent,2);
  307.       checkqueue();
  308.       //      PostMessage(MainHWindow, WM_CHECKQUEUE, 0, 0);
  309.       }
  310.    
  311.    // else do your normal stuff
  312.    
  313.    else
  314.       {
  315.       DefWndProc( Msg );
  316.       }
  317.    }
  318.  
  319. void TMyWindow::WMChar(RTMessage Msg)
  320.    { 
  321.    callthing *callevent;
  322.    
  323.    // if keyboard was on and NOT up and down is enabled then continue
  324.    
  325.    if (keyboard_on == 1)
  326.       {
  327.       callevent = new callthing;
  328.       
  329.       callevent->func = keyboard_keyup;
  330.       callevent->arg1 = Msg.WParam;
  331.       callevent->kind = 2;
  332.       
  333.       calllists.insert(callevent,2);
  334.       checkqueue();
  335.       //      PostMessage(MainHWindow, WM_CHECKQUEUE, 0, 0);
  336.       }
  337.    
  338.    // else do your normal stuff
  339.    
  340.    else
  341.       {
  342.       DefWndProc( Msg );
  343.       }
  344.    }
  345.  
  346. void TMyWindow::GetWindowClass(WNDCLASS& WndClass)
  347.    {
  348.    TWindow::GetWindowClass( WndClass );
  349.    WndClass.lpszMenuName = "Logo";
  350.    WndClass.hIcon = LoadIcon( GetApplication()->hInstance, "LogoIcon");
  351.    }
  352.  
  353. void TMyWindow::Paint( HDC PaintDC, PAINTST